$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        dataGird:null,
        frame:null,
        init:function () {
            this.frame = $('[name=detailFrame]');
            this.dataGrid = new xhDataGrid($('#meetingList'));
            this.dataGrid.parseToolbar().init(baseUrl+'lm/meeting/getMeetingList',this.funObj().getParams()).activeButton([],['bt_list_del']);
            $('[name=dayFrame]').focus();
            this.listener();
            this.funObj().bindDataGridEvent();
        },
        listener:function () {
            var $this = this;

            //新增
            $('#bt_list_add').click(function () {
                $this.funObj().addForm();
            });

            //删除
            $('#bt_list_del').click(function () {
                if (xhExtra.buttonDisabled($(this))) {
                    return false;
                }
                $this.funObj().askDel();
            });

            //搜索
            $('#bt_list_search').click(function () {
                $this.funObj().doSearch()
            });
            xhTool.bindDocKeyDown($('#bt_list_search'));

        },
        funObj:function () {
            var $this = this;
            return {
                addForm:function () {
                    $('#targetTr').show();
                    $('#targetTr').prev().hide();
                    $this.frame[0].contentWindow.location = baseUrl + 'lm/meeting/meetingForm';
                },
                askDel:function () {
                    var id = $this.dataGrid.getSelectValue('iUMRId');
                    xhExtra.askChangeStatus('lm/meeting/delMeeting',{id:id},$this.dataGrid, '确定要删除这个会议申请么?', function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                    });
                },
                doSearch:function () {
                    $this.dataGrid.reload($this.funObj().getParams());
                },
                getParams:function () {
                   return  {
                       key:xhExtra.getValue($('#list_search')),
                       room:xhExtra.getValue($('#select_room')),
                       startTime:xhExtra.getValue($('#List_Search_StartTime')),
                       endTime:xhExtra.getValue($('#List_Search_EndTime'))
                   }
                },
                backToList:function () {
                    $('#targetTr').hide();
                    $('#targetTr').prev().show();
                    $this.dataGrid.reload();
                },
                bindDataGridEvent:function () {
                    $this.dataGrid.onDblClickRow  = function(rowIndex, rowData){
                        $('#targetTr').show();
                        $('#targetTr').prev().hide();
                        $this.frame[0].contentWindow.location = baseUrl + 'lm/meeting/meetingForm?id='+rowData['iUMRId'];
                    };
                }
            }
        }
    }
};